﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.IBLL;
using HZ.Supervise.Model;
using HZ.Supervise.Model.Enum;

namespace HZ.Supervise.Web.Secondphase.NewReport
{
    public partial class SortPSL_Total : BasePage
    {
        HZ.Supervise.IBLL.IExecuteContext iEC = HZ.Supervise.BLLFactory.ExecuteContext();
        string source = "";

        public SortPSL_Total()
        {
            this.ModuleNo = Module.药品统计分析.ToString();
            this.PageOperateType = OperateType.药品分类统计.ToString();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.AreaControl1.InitAreaID = CurrentAccount.GetUser().Org.Area.AreaID;
                DataBind();
                DataBindNew();
            }
        }

        /// <summary>
        /// 绑定数据方法
        /// YD
        /// 2011-3-30 19:18
        /// </summary>
        private void DataBind()
        {
            int t = 0;
            //查询条件    by张雄  2011.5.4
            string orderby = this.OrderFileds.SelectedItem.Value + "  " + this.OrderType.SelectedItem.Value;

            string sortname = SortControls1.SortName;
            string areaid = AreaControl1.SelectedAreaID;
            System.Data.DataTable dt = iEC.ExecutePagePSL_Sort(1,areaid, sortname, orderby, this.AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out t);

            AspNetPager1.RecordCount = t;

            gvwPSLInfo.PageSize = AspNetPager1.PageSize;

            this.gvwPSLInfo.DataSource = dt;
            HZ.Supervise.Web.Function.ChangeRate_PS_More(dt, "DistributeRate", "WareHouseRate");

            this.gvwPSLInfo.DataBind();
        }

        /// <summary>
        /// 绑定数据 
        /// by张雄  2011.5.30
        /// </summary>
        private void DataBindNew()
        {
            int t = 0;
            string orderby = this.OrderFileds.SelectedItem.Value + "  " + this.OrderType.SelectedItem.Value;

            string sortname = SortControls1.SortName;
            string areaid = AreaControl1.SelectedAreaID;
            System.Data.DataTable dt = iEC.ExecutePagePSL_Sort(0, areaid, sortname, orderby, this.AspNetPager2.CurrentPageIndex, AspNetPager2.PageSize, out t);

            AspNetPager2.RecordCount = t;

            GridView1.PageSize = AspNetPager2.PageSize;

            this.GridView1.DataSource = dt;
            HZ.Supervise.Web.Function.ChangeRate_PS_More(dt, "DistributeRate", "WareHouseRate");

            this.GridView1.DataBind();
        }

        /// <summary>
        /// 查询数据事件
        /// 董辉
        /// 2011-3-30 19:17
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void btn_chaxun_Click(object sender, EventArgs e)
        {
            //汇总
            AspNetPager1.CurrentPageIndex = 1;
            //县区
            AspNetPager2.CurrentPageIndex = 2;
        }

        /// <summary>
        /// 分页事件
        /// 董辉
        /// 2011-3-30 19:19
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            DataBind();
            //by张雄    
            this.divTable.Visible = true;
            this.divTable.Attributes.Add("style", "display:block");
            this.Page.ClientScript.RegisterStartupScript(this.GetType(), "myscript", "<script>document.getElementById(\"btnShowImg\").value=\"隐藏县区数据\";</script>");

        }
        /// <summary>
        /// 分页事件    县区
        /// by张雄  2011.5.30
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void AspNetPager2_PageChanged(object sender, EventArgs e)
        {
            DataBindNew();

            this.divTable.Visible = true;
            this.divTable.Attributes.Add("style", "display:block");
            this.Page.ClientScript.RegisterStartupScript(this.GetType(), "myscript", "<script>document.getElementById(\"btnShowImg\").value = \"隐藏县区数据\"</script>");
        }

        /// <summary>
        /// 导出数据事件    汇总
        /// 董辉
        /// 2011-3-30 19:19
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void btnExcel_Click(object sender, EventArgs e)
        {
            //modify    by  张雄    
            int t = 0;

            string orderby = this.OrderFileds.SelectedItem.Value + "  " + this.OrderType.SelectedItem.Value;
            string sortname = SortControls1.SortName;
            string areaid = AreaControl1.SelectedAreaID;
            System.Data.DataTable dt = iEC.ExecutePagePSL_Sort(1,areaid,sortname, orderby, 0, 0, out t);

            HZ.Supervise.Web.Function.ChangeRate_PS_More(dt, "DistributeRate", "WareHouseRate");



            ExportFile.Instance.ExportData(dt, gvwPSLInfo, this.Page);
        }

        /// <summary>
        /// 导出数据    县区
        /// by张雄  2011.5.30
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void btnExcel1_Click(object sender, EventArgs e)
        {
            //modify    by  张雄    
            int t = 0;

            string orderby = this.OrderFileds.SelectedItem.Value + "  " + this.OrderType.SelectedItem.Value;
            string sortname = SortControls1.SortName;
            string areaid = AreaControl1.SelectedAreaID;
            System.Data.DataTable dt = iEC.ExecutePagePSL_Sort(0, areaid, sortname, orderby, 0, 0, out t);

            HZ.Supervise.Web.Function.ChangeRate_PS_More(dt, "DistributeRate", "WareHouseRate");

            ExportFile.Instance.ExportData(dt, GridView1, this.Page);
        }


    }
}
